package com.zebra.base.vo;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zebra.base.po.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName QueryForm
 * @Description TODO QueryForm 用于查询带分页的查询
 * @Author 消魂钉
 * @Date 6/1 0001 14:30
 */
@Data
public class QueryForm<T extends BaseEntity> extends BaseForm<T> {


    public final static Integer ORDER_ASC = 0;
    public final static Integer ORDER_DESC = 1;

    public QueryForm() {
    }

    public QueryForm(String sortItem, Integer sortOrder, Long pageSize, Long total, Long pageCount, Long currentPage) {
        this.sortItem = sortItem;
        this.sortOrder = sortOrder;
        this.pageSize = pageSize;
        this.total = total;
        this.pageCount = pageCount;
        this.currentPage = currentPage;
    }

    @JsonIgnore
    private String sortItem;
    @JsonIgnore
    private Integer sortOrder;

    @JsonIgnore
    public String getOrderBy()
    {
        if (StrUtil.isEmpty(sortItem))
        {
            return "";
        }
        return StrUtil.toUnderlineCase(sortItem) + " " + (sortOrder.compareTo(ORDER_ASC)==0?"asc":"desc");
    }


    /**
     * 每一页的总条数
     */
    @ApiModelProperty(name = "pageSize",value="每一页的总条数")
    protected Long pageSize = 20L;

    /**
     * 总条数
     */
    @ApiModelProperty(name="total",value = "总条数")
    protected Long total;

    /**
     * 总页数
     */
    @ApiModelProperty(name="pageCount",value = "总页数")
    protected Long pageCount;

    /**
     * 当前页数
     */
    @ApiModelProperty(name = "currentPage",value = "当前页数")
    protected Long currentPage = 1L;


    /**
     * 从Vue转化成Mybatis-plus 封装好的分页
     * @return
     */
    @JsonIgnore
    public Page getPage() {
        return new Page(this.getCurrentPage(), this.getPageSize());
    }

}
